<template>
  <div>
    <elm-page-tb>
      <template #top>
        <el-input placeholder="请查询输入内容" size="mini" prefix-icon='el-icon-search' style="width:250px;" v-model="postData.name" clearable></el-input>
        <right>
          <el-button-group>
            <el-button icon="el-icon-search" size="mini" @click="tablebinding(activeName)">查询</el-button>
            <elm-open-button :url="activeName+'_edit'" title="新增"  width="900" height="90%">新增</elm-open-button>
          </el-button-group>
        </right>
      </template>
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="线索" name="lead">
          <elm-table ref="lead" url="/business/crm/leadoppo/lead/GetData" :post-data="postData" style="height: calc(100vh - 228px)">
            <el-table-column prop="sys_code_key" label="线索号" align="center" width="120"></el-table-column>
            <el-table-column prop="xqms" label="需求描述" align="left" header-align="center"></el-table-column>
            <el-table-column prop="select_name" label="客户名称" align="left" header-align="center" min-width="100"></el-table-column>
            <el-table-column prop="lxr_xm" label="联系人" align="center"  width="70"></el-table-column>
            <el-table-column prop="lxr_zw" label="联系人职务" align="center" width="100"></el-table-column>
            <el-table-column prop="lxr_dh" label="联系人电话" align="center" width="120"></el-table-column>
            <el-table-column prop="zt" label="状态" align="center"  width="70"></el-table-column>
            <el-table-column prop="dj" label="优先级" align="center"  width="120"></el-table-column>
            <el-table-column prop="ly" label="线索来源" align="left" header-align="center"></el-table-column>
            <el-table-column prop="fzxs_mc" label="跟进人" align="center" width="100"></el-table-column>
            <el-table-column fixed="right" label="操作" width="120px" align="center">
              <template v-slot="scope">
                <elm-open-button url="lead_edit" title="编辑" width="900" height="90%" :data="{ model: scope.row }" type="text">编辑</elm-open-button>
                <elm-delete-button  type="text" size="mini" url="/business/crm/leadoppo/lead/Delete" :data="{ id: scope.row.id }">删除</elm-delete-button>
                <elm-open-button url="opportunity_edit" title="补齐数据" width="900" height="60%" :data="leadToOpportunity(scope.row)" type="text">转换</elm-open-button>
              </template>
            </el-table-column>
          </elm-table>
        </el-tab-pane>
        <el-tab-pane label="商机" name="opportunity">
          <elm-table ref="opportunity" url="/business/crm/leadoppo/opportunity/GetData" :post-data="postData" style="height: calc(100vh - 228px)">
            <el-table-column prop="jd" label="阶段" align="center"  width="80"></el-table-column>
            <el-table-column prop="sys_code_key" label="商机号" align="center" width="100"></el-table-column>
            <el-table-column prop="name" label="商机名" align="left" header-align="center"  width="150"></el-table-column>
            <el-table-column prop="kh_name_mc" label="客户" align="left" header-align="center"  width="150"></el-table-column>
            <el-table-column prop="lxr_xm" label="联系人" align="center"  width="70"></el-table-column>
            <el-table-column prop="lxr_zw" label="联系人职务" align="center"   width="100"></el-table-column>
            <el-table-column prop="lxr_dh" label="联系人电话" align="center"   width="120"></el-table-column>
            <el-table-column prop="fzxs_mc" label="跟进人" align="center" width="70"></el-table-column>
            <el-table-column prop="zt" label="状态" align="center"  width="70"></el-table-column>
            <el-table-column prop="yjgbrq" label="关闭日期" align="center"  width="160" :formatter="formatDateTime"></el-table-column>
            <el-table-column prop="djrq" label="登记日期" align="center"  width="160" :formatter="formatDateTime"></el-table-column>
            <el-table-column prop="yjje" label="预计金额(万元)" align="right" header-align="center" width="120"></el-table-column>
            <el-table-column prop="ly" label="来源" align="left" header-align="center"  width="150"></el-table-column>
            <el-table-column prop="gl" label="成功概率" align="center" width="80">
              <template v-slot="scope">
                {{scope.row.gl}}%
              </template>
            </el-table-column>
            <el-table-column prop="fx" label="风险程度" align="center" width="80"></el-table-column>
            <el-table-column prop="remark" label="备注" align="left" header-align="center"></el-table-column>
            <el-table-column fixed="right" label="操作" width="120px" align="center">
              <template v-slot="scope">
                <elm-open-button url="opportunity_edit" title="编辑" width="900" height="90%" :data="{ model: scope.row }" type="text">编辑</elm-open-button>
                <elm-delete-button  type="text" size="mini" url="/business/crm/leadoppo/opportunity/Delete" :data="{ id: scope.row.id }">删除</elm-delete-button>
                <elm-open-button url="lead_edit" title="补齐数据" width="900" height="60%" :data="opportunityToLead(scope.row)" type="text">转换</elm-open-button>
              </template>
            </el-table-column>
          </elm-table>
        </el-tab-pane>
      </el-tabs>
    </elm-page-tb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      activeName: 'lead',
      postData: { name: null}
    }
  },
  created() {
  },
  methods: {
    leadToOpportunity(row){
      var model={
        id:elm.newGuid(),
        name:row.xqms,
        ly:row.ly,
        fzxs:row.fzxs,
        remark:row.remark,
        kh_name:row.kh_name,
        lxr_xm:row.lxr_xm,
        lxr_zw:row.lxr_zw,
        lxr_dh:row.lxr_dh,
        lxr_email:row.lxr_email,
        lx:"新商机",
        zt:"新建",
        jd:"未接触"
      };
      return {model:model,is_turn:true};
    },
    opportunityToLead(row){
      var model={
        id:elm.newGuid(),
        xqms:row.name,
        ly:row.ly,
        fzxs:row.fzxs,
        remark:row.remark,
        kh_name:row.kh_name,
        lxr_xm:row.lxr_xm,
        lxr_zw:row.lxr_zw,
        lxr_dh:row.lxr_dh,
        lxr_email:row.lxr_email,
        zt:"新线索"
      };
      return {model:model,is_turn:true};
    }
  }
}
</script>
